﻿using System;
using ThangNM_LIB.EO;
using ThangNM_LIB.FUNC;

namespace ThangNM.UserControl
{
    public partial class MsgUC : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void setClearMsg(Boolean isFixNotify = false)
        {
            divMsg.Visible = false;
            lblMsg.Text = "";
            if (isFixNotify)
                setFixNotify();
        }

        public void setNotifications(Int16 iType, string strMsg, String strMsgFull = null)
        {
            string strType = "";
            switch (iType)
            {
                case ConstEx.FunctionSetMsg.SUCCESS:
                    ltlIcon.Text = "<i class=\"fa fa-check-circle\"></i>";
                    strType = "alert alert-success alert-dismissable";
                    break;
                case ConstEx.FunctionSetMsg.INFO:
                    ltlIcon.Text = "<i class=\"fa fa-info-circle\"></i>";
                    strType = "alert alert-info alert-dismissable";
                    break;
                case ConstEx.FunctionSetMsg.WARNING:
                    ltlIcon.Text = "<i class=\"fa fa-warning\"></i>";
                    strType = "alert alert-warning alert-dismissable";
                    break;
                case ConstEx.FunctionSetMsg.ERROR:
                case ConstEx.FunctionSetMsg.DANGER:
                    ltlIcon.Text = "<i class=\"fa fa-times-circle-o\"></i>";
                    strType = "alert alert-danger alert-dismissable";
                    if (String.IsNullOrEmpty(strMsgFull))
                        strMsgFull = strMsg;
                    (new Logs()).WriteLog_To_DB(new LogEO(strMsgFull, ConstEx.Log_iType.EXCEPTION), false);
                    if (OtherEx.getAppSettings("SHOW_FULL_ERROR", "0").Equals("1"))
                        strMsg = strMsgFull;
                    break;
            }
            divMsg.Visible = true;
            divMsg.Attributes.Add("class", strType);
            lblMsg.Text = (String.IsNullOrEmpty(lblMsg.Text) ? "" : lblMsg.Text + "<BR />") + strMsg;
        }

        protected void setFixNotify()
        {
            divMsg.Attributes.CssStyle.Add("bottom", "0px");
            divMsg.Attributes.CssStyle.Add("margin-bottom", "0px");
            divMsg.Attributes.CssStyle.Add("position", "fixed");
            divMsg.Attributes.CssStyle.Add("z-index", "1992");
        }
    }
}